

const OSS = require('ali-oss');
// import {nanoid} from nanoid;
const nanoid=require("nanoid")
const client = new OSS({
  

  accessKeyId: 'LTAI5tJuD4fXX5qwo2LX7RVK',  // 查看你自己的阿里云KEY
  accessKeySecret: 'EdpzhdKGQsePsqqBCgKMiVpsEYYdd5', // 查看自己的阿里云KEYSECRET
  bucket: 'zhen-sheep', // 你的 OSS bucket 名称
  region: 'oss-cn-beijing', // bucket 所在地址，我的是 华北2 北京
  endpoint:'oss-cn-beijing.aliyuncs.com',
  secure:true
});
export async function uploadimg(file){
  const uuid=nanoid.nanoid();
  const index=file.name.lastIndexOf('.');
  const hou=file.name.substring(index+1);
  const key=uuid+"."+hou;
  var jieguo='';
   await client.multipartUpload(`sheep/${key}`,file,{
    process:function(e){
      console.log(e);
      return "hh";
    } 
  })
  // .then((result) => {
  //   jieguo=result.name;
  //   console.log("https://zhen-sheep.oss-cn-beijing.aliyuncs.com/sheep/"+key);
  //   console.log(result);
    
  //   return "https://zhen-sheep.oss-cn-beijing.aliyuncs.com/img/"+result.name;
  // }).catch((err) => {
  //   console.log(err);
  //   return "空";
  // })

  return "https://zhen-sheep.oss-cn-beijing.aliyuncs.com/sheep/"+key;
}